﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.workers {
    import Classes.*;
    import Classes.util.*;
    import Classes.inventory.*;
    import Modules.trains.*;

    public class TrainWorkers extends Workers {

        public static const OP_BUY:String = "buy";
        public static const OP_SELL:String = "sell";
        private static const TRAIN_NAME:String = "trainName";
        private static const OPERATION:String = "operation";
        private static const COMMODITY_NAME:String = "commodityName";
        private static const TIME_SENT:String = "timeSent";
        private static const PAYOUT_BONUS_UNLOCK_FLAG:String = "cux_train_bonus";

        private var m_xp:int = 0;
        private var m_coins:int = 0;
        private var m_commodity:int = 0;
        private var m_autoAccept:Boolean = false;
        private var m_isWelcomeWorker:Boolean = false;

        public function TrainWorkers(){
            this.recalculateRewards();
        }
        public function get xp():int{
            return (this.m_xp);
        }
        public function set xp(_arg1:int):void{
            this.m_xp = _arg1;
        }
        public function get coins():int{
            return (this.m_coins);
        }
        public function set coins(_arg1:int):void{
            this.m_coins = _arg1;
        }
        public function get commodity():int{
            return (this.m_commodity);
        }
        public function set commodity(_arg1:int):void{
            this.m_commodity = _arg1;
        }
        public function get commodityType():String{
            return (getAttribute(COMMODITY_NAME, Commodities.GOODS_COMMODITY));
        }
        public function set commodityType(_arg1:String):void{
            setAttribute(COMMODITY_NAME, _arg1);
        }
        public function get itemName():String{
            return (getAttribute(TRAIN_NAME, ""));
        }
        public function set itemName(_arg1:String):void{
            setAttribute(TRAIN_NAME, _arg1);
            this.recalculateRewards();
        }
        public function get operation():String{
            return (getAttribute(OPERATION, OP_BUY));
        }
        public function set operation(_arg1:String):void{
            setAttribute(OPERATION, _arg1);
            this.recalculateRewards();
        }
        public function get timeSent():int{
            return (getAttribute(TIME_SENT, 0));
        }
        public function set timeSent(_arg1:int):void{
            setAttribute(TIME_SENT, _arg1);
        }
        private function recalculateRewards():void{
            var _local2:String;
            this.m_xp = 0;
            this.m_coins = 0;
            this.m_commodity = 0;
            var _local1:Item = Global.gameSettings.getItemByName(this.itemName);
            if (_local1){
                _local2 = _local1.trainPayout;
                switch (this.operation){
                    case OP_BUY:
                        this.m_commodity = Math.ceil((Global.gameSettings.getTieredInt(_local2, getWorkerCount()) * this.getPayoutBonus()));
                        break;
                    case OP_SELL:
                        this.m_coins = Math.ceil((Global.gameSettings.getTieredInt(_local2, getWorkerCount()) * this.getPayoutBonus()));
                        break;
                };
            };
        }
        private function getPayoutBonus():Number{
            var _local1:Number = 1;
            var _local2:Boolean = ((Global.player.getSeenFlag(PAYOUT_BONUS_UNLOCK_FLAG)) || (Global.player.getSeenSessionFlag(PAYOUT_BONUS_UNLOCK_FLAG)));
            if ((((getWorkerCount() > 0)) && (_local2))){
                _local1 = Global.gameSettings.getNumber("trainBonusMult", 1.1);
            };
            return (_local1);
        }
        override public function get maxWorkers():int{
            var _local1:Item = Global.gameSettings.getItemByName(this.itemName);
            var _local2:int;
            if (_local1.workers){
                _local2 = _local1.workers.amount;
            };
            return (_local2);
        }
        override public function addWorker(_arg1:String, _arg2:Boolean=false):int{
            var _local3:int = super.addWorker(_arg1, _arg2);
            this.recalculateRewards();
            return (_local3);
        }
        override public function loadObject(_arg1:Object):void{
            super.loadObject(_arg1);
            this.recalculateRewards();
        }
        public function speedUp():void{
            var _local2:uint;
            var _local3:uint;
            var _local1:Item = Global.gameSettings.getItemByName(this.itemName);
            if (_local1){
                _local2 = uint((GlobalEngine.getTimer() / 1000));
                _local3 = _local1.trainTripTime;
                this.timeSent = (this.timeSent - (_local3 - (_local2 - this.timeSent)));
            };
            GameTransactionManager.addTransaction(new TSpeedUpTrain());
        }

    }
}//package Modules.workers 
